using System;
using System.Collections.Generic;
using System.Windows.Forms;
using TaugeFramework.Classes;
using TaugeLibrary.Classes;
using TaugeLibrary.Interfaces;
using TaugeFramework.Forms;
using TaugeFramework.BusinessUnit.User;

namespace TaugeFramework
{
    static class Program
    {

        public static Database dbsys = new Database();
        public static Database dbdata = new Database();


        public static string AppPath;
        public static string ReportPath;
        public static string UpdatePath;
        public static string UpdateFile;


        public static string FORMAT_DATE = "dd/MM/yyyy";
        public static string FORMAT_TIME = "hh:mm:ss";
        public static string FORMAT_DATETIME = "dd/MM/yyyy hh:mm:ss";
        public static string FORMAT_INT = "####";
        public static string FORMAT_DOUBLE = "#,###.##";

        public static bool IsDebugMode;


        public static TaugeFramework.Classes.TaugeFramework Framework = new TaugeFramework.Classes.TaugeFramework();

        public static frmMain fMain;

        public static UserAccount ActiveUser = new UserAccount(Framework);
        //public static CompanyStructure ActiveCompany = new CompanyStructure();        


        public static void LoadINI(string p_file)
        {
            IniFile ini = new IniFile(p_file);
            dbsys.ConnectionData.DBServer = ini.readString("Database", "svr", ".");
            dbsys.ConnectionData.DBName = ini.readString("Database", "db", "master");
            dbsys.ConnectionData.DBAuth = ini.readBoolean("Database", "auth", true);
            dbsys.ConnectionData.DBUser = ini.readString("Database", "usr", "sa");
            dbsys.ConnectionData.DBPasswordHashed = ini.readString("Database", "pwd", "");


            dbdata.ConnectionData.DBServer = ini.readString("Database", "svr", ".");
            dbdata.ConnectionData.DBName = ini.readString("Database", "db", "master");
            dbdata.ConnectionData.DBAuth = ini.readBoolean("Database", "auth", true);
            dbdata.ConnectionData.DBUser = ini.readString("Database", "usr", "sa");
            dbdata.ConnectionData.DBPasswordHashed = ini.readString("Database", "pwd", "");



            UpdatePath = ini.readString("DBUpdate", "path", AppPath + @"\Update\");
            UpdateFile = ini.readString("DBUpdate", "filename", AppPath + "dbup.xml");

            ReportPath = ini.readString("Report", "path", AppPath + @"\Report\");

            FORMAT_DATE = ini.readString("Format", "date", "dd/MM/yyyy");
            FORMAT_TIME = ini.readString("Format", "time", "hh:mm:ss");
            FORMAT_DATETIME = ini.readString("Format", "datetime", "dd/MM/yyyy hh:mm:ss");
            FORMAT_INT = ini.readString("Format", "int", "####");
            FORMAT_DOUBLE = ini.readString("Format", "double", "#,###.##");

            IsDebugMode = ini.readBoolean("Programmer", "debug", false);


            //update
            //DatabaseUpdater du = new DatabaseUpdater(Program.dbsys);
            //du.Update_XML(Program.UpdatePath + @"\sys\", Program.UpdateFile);




        }

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string [] args)
        {
            AppPath = Application.StartupPath;
            if (args != null && args.Length > 0)
                LoadINI(args[0]);
            else
                LoadINI(AppPath + @"\default.INI");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            fMain = new frmMain();
            Application.Run(fMain);
        }

        public static void DebugBox(string p_msg)
        {
            frmDebugMessage fd = new frmDebugMessage();
            fd.txtDebug.Text = p_msg;
            fd.MdiParent = fMain;
            fd.Show();
        }
    }
}